package com.block.account.service.bill;

import cn.hutool.core.util.StrUtil;
import com.block.account.enums.AccountTypeEnum;
import com.block.account.factory.AccountBillFactory;
import com.block.account.factory.BillInfoFactory;
import com.block.account.service.IBillInfoChannelService;
import com.block.account.service.IBillInfoProductService;
import com.block.account.service.IBillInfoService;
import com.block.common.constant.AppRspCodeConstant;
import com.block.common.vo.ResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

@Service
public class BillInfoServiceImpl implements IBillInfoService {

    @Autowired
    IBillInfoChannelService billInfoChannelService;
    @Autowired
    IBillInfoProductService billInfoProductService;

    /**
     * 生成订单信息
     * @param dateInfo
     * @param dataId
     * @param dataType
     * @return
     */
    @Override
    public ResponseVo generatorBillInfo(String dateInfo, String dataId, String dataType){

        /**
         * 如果没有指定 账单日期；则生成今日的账单
         */
        if (StrUtil.isEmpty(dateInfo)){
            dateInfo = LocalDate.now().toString();
        }

        if (StrUtil.equals(AccountTypeEnum.CHAN.getValue(), dataType)){
            billInfoChannelService.generatorBillInfo(dateInfo, dataId);
        }else if (StrUtil.equals(AccountTypeEnum.PROD.getValue(), dataType)){
            billInfoProductService.generatorBillInfo(dateInfo, dataId);
        }else{
            billInfoChannelService.generatorBillInfo(dateInfo, dataId);
            billInfoProductService.generatorBillInfo(dateInfo, dataId);
        }

        return new ResponseVo(AppRspCodeConstant.SUCCESS);
    }

    /**
     * 产品/渠道每日消耗  申请入账
     * @param recordId
     * @param recordType
     * @param operatorId
     * @param operatorName
     * @return
     */
    @Override
    public ResponseVo xhApplyEnter(String recordId, String recordType, String operatorId, String operatorName){
        return BillInfoFactory.getService(recordType).xhApplyEnter(recordId, operatorId, operatorName);
    }

    @Override
    public ResponseVo genAccountBill(String dateInfo, String accountId, String accountType) {

        AccountBillFactory.getService(accountType).genAccountBillInfo(dateInfo, accountId);

        return new ResponseVo(AppRspCodeConstant.SUCCESS);
    }

}
